<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
    <link rel="stylesheet" href="./index.css" />
    <script src="https://unpkg.com/vue@3"></script>
  </head>
 
  <body>
    <div id="app"></div>
    <template id="root">
      <div class="box">
        <!-- 左侧背景 -->
        <div class="left_contain"></div>
        <!-- 右侧内容 -->
        <div class="right">
          <div class="right_hd">
            <!-- logo -->
            <div class="logo">
              <img src="https://s1.ax1x.com/2023/04/14/ppzXmFI.png" alt="" />
              <span>小米账号</span>
            </div>
            <!-- 右侧选项 -->
            <div class="r_option">
              <a href="javascript:;">用户协议</a>
              <a href="javascript:;">隐私政策</a>
              <a href="javascript:;">帮助中心</a>
              <select name="" id="">
                <option value="">中文(简体)</option>
                <option value="">中文(繁体)</option>
                <option value="">English</option>
              </select>
            </div>
          </div>
          <div class="right_body">
            <div class="log_reg">
              <a :class="isActice?['isActice']:[]" @click="login">登录</a>
              <a :class="isActice?[]:['isActice']" @click="register">注册</a>
            </div>
            <!-- 登录 -->
            <div class="login_content" v-if="isActice">
              <form action="">
                <div class="uname">
                  <input type="text" placeholder="邮箱/手机号码/小米ID" class="ipt" v-model="username" />
                </div>
                <div class="pwd">
                  <input type="password" placeholder="密码" class="ipt" v-model="password" />
                </div>
                <div class="change">
                  <input type="checkbox" v-model="isChecked" @click="l_change" />
                  <span
                    >已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
                    <a href="javascript:;">隐私政策</a>
                  </span>
                </div>
              </form>
              <button class="log_btn" @click="goLogin">登录</button>
              <div class="forget">
                <a href="javascript:;">忘记密码？</a>
                <a href="javascript:;">手机号登录</a>
              </div>
              <div class="other">其他方式登录</div>
              <div class="other_content">
                <img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
              </div>
            </div>
            <!-- 注册 -->
            <div class="register_content" v-else>
              <form action="">
                <div>
                  <select class="ipt" v-model="cityvalue">
                    <option :value="item.value" v-for="item in city">{{ item.text }}</option>
                  </select>
                </div>
                <div>
                  <input type="text" placeholder="手机号" class="ipt" v-model.number="phone" />
                </div>
                <div class="yzm">
                  <input type="password" placeholder="密码" class="ipt" v-model.trim="r_password" />
                  <!-- <input type="text" placeholder="请输入验证码" class="ipt" maxlength="4" v-model.number="yzm" /> -->
                  <!-- <span>获取验证码</span> -->
                </div>
                <div class="change">
                  <input type="checkbox" v-model="isChecked1" @click="r_change" />
                  <span
                    >已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
                    <a href="javascript:;">隐私政策</a>
                  </span>
                </div>
              </form>
              <button class="reg_btn" @click="goRegister">注册</button>
              <div class="Unavailable">收不到验证码？</div>
              <div class="other">其他方式登录</div>
              <div class="other_content">
                <img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </template>
    <script>
        Vue.createApp({
          template: '#root',
          data() {
            return {
              isActice: true,
              username: '',
              password: '',
              r_password: '',
              phone: '',
              isChecked: false,
              isChecked1: false,
              userList: [],
              cityvalue: 'China',
              city: [
                { value: 'China', text: '中国' },
                { value: 'mg', text: '美国' },
                { value: 'other', text: '其他' }
              ],
              otherLogin: [
                {
                  id: 1,
                  name: '支付宝',
                  path: 'https://s1.ax1x.com/2023/04/14/p9SEuQJ.png'
                },
                {
                  id: 2,
                  name: '微信',
                  path: 'https://s1.ax1x.com/2023/04/14/p9SEGFK.png'
                },
                {
                  id: 3,
                  name: 'QQ',
                  path: 'https://s1.ax1x.com/2023/04/14/p9SEJJO.png'
                },
                {
                  id: 4,
                  name: '微博',
                  path: 'https://s1.ax1x.com/2023/04/14/p9SEUQH.png'
                }
              ]
            }
          },
          methods: {
            // 登录注册切换
            login() {
              this.isActice = !this.isActice
            },
            register() {
              this.isActice = !this.isActice
            },
            // 用户条款勾选
            l_change() {
              this.isChecked = !this.isChecked
            },
            r_change() {
              this.isChecked1 = !this.isChecked1
            },
            // 登录
            goLogin() {
              if (this.username == '' || this.password == '') {
                alert('账号或密码为空，请输入')
              } else {
                if (!this.isChecked) {
                  alert('请同意用户条款')
                } else {
                  this.userList.forEach(item => {
                    if (item.phone == this.username && item.password == this.password) {
                      alert('登录成功')
                    } else {
                      alert('登录失败')
                    }
                  })
                }
              }
            },
            // 注册
            goRegister() {
              if (this.phone == '' || this.r_password == '') {
                alert('输入不能为空')
              } else {
                if (!this.isChecked1) {
                  alert('请同意用户条款')
                } else {
                  const regCN = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
                  if (!regCN.test(this.phone)) {
                    alert('请输入正确的手机号')
                  } else {
                    let isRegister
                    this.userList.forEach(item => {
                      if (item.phone == this.phone) {
                        isRegister = true
                      } else {
                        isRegister = false
                      }
                    })
                    if (isRegister) {
                      alert('用户名已存在')
                    } else {
                      let data = {
                        id: +new Date(),
                        phone: this.phone,
                        password: this.r_password,
                        city: this.cityvalue
                      }
                      this.userList.push(data)
                      alert('注册成功')
                      console.log(this.userList)
                      this.phone = ''
                      this.r_password = ''
                    }
                  }
                }
              }
            }
          }
        }).mount('#app')
      </script>
 </body>
</html>